<div>
  <ul class="nav nav-tabs" role="tablist">
    <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">合同操作</a></li>
    <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">合同记录</a></li>
  </ul>

  <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="home">
        <form id="edit-form" style="margin-top: 20px;" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">

            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
                <div class="col-xs-12 col-sm-8">
                    <input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" value="{$row.name|htmlentities}">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('Gender')}:</label>
                <div class="col-xs-12 col-sm-8">

                    <select  id="c-gender" data-rule="required" class="form-control selectpicker" name="row[gender]">
                        {foreach name="genderList" item="vo"}
                            <option value="{$key}" {in name="key" value="$row.gender"}selected{/in}>{$vo}</option>
                        {/foreach}
                    </select>

                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('Mobile')}:</label>
                <div class="col-xs-12 col-sm-8">
                    <input id="c-mobile" data-rule="required" class="form-control" name="row[mobile]" type="text" value="{$row.mobile|htmlentities}">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('Idcard')}:</label>
                <div class="col-xs-12 col-sm-8">
                    <input id="c-idcard" data-rule="required" class="form-control" name="row[idcard]" type="text" value="{$row.idcard|htmlentities}">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('CurrentAddress')}:</label>
                <div class="col-xs-12 col-sm-8">
                    <input id="c-currentAddress" data-rule="required" class="form-control" name="row[currentAddress]" type="text" value="{$row.currentAddress|htmlentities}">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('PermanentAddress')}:</label>
                <div class="col-xs-12 col-sm-8">
                    <input id="c-permanentAddress" data-rule="required" class="form-control" name="row[permanentAddress]" type="text" value="{$row.permanentAddress|htmlentities}">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('Urgent_name')}:</label>
                <div class="col-xs-12 col-sm-8">
                    <input id="c-urgent_name" data-rule="required" class="form-control" name="row[urgent_name]" type="text" value="{$row.urgent_name|htmlentities}">
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">{:__('Urgent_mobile')}:</label>
                <div class="col-xs-12 col-sm-8">
                    <input id="c-urgent_mobile" data-rule="required" class="form-control" name="row[urgent_mobile]" type="text" value="{$row.urgent_mobile|htmlentities}">
                </div>
            </div>


            <hr/>
            <h3>合同模版</h3>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">入职公司:</label>
                <div class="col-xs-12 col-sm-8">
                    <select class="form-control" data-rule="required" id="company_id" name="row[company_id]">
                        {if $companyList}
                        {foreach $companyList as $list}
                        <option {if $list.id == $row.company_id}selected{/if} value="{$list.id}">{$list.name}</option>
                        {/foreach}
                        {/if}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">合同:</label>
                <div class="col-xs-12 col-sm-8">
                    <input type="hidden" id="default_templateId" value="{$row.templateId}">
                    <select class="form-control" data-rule="required" id="templateId" name="row[templateId]">
                    </select>
                    <!-- <a target="_blank" href="/uploads/salary/doc/劳动合同.docx">下载合同模版文件</a> -->
                </div>
            </div>
            <hr/>
            <h3>合同期限</h3>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-2">合同期限:</label>
                <div class="col-xs-12 col-sm-8">

                    {php}
                        if ($row['contract_start_date']) {
                            $contract_start_date = $row['contract_start_date'];
                        } else {
                            $contract_start_date = date('Y-m-d');
                        }

                        if ($row['contract_end_date']) {
                            $contract_end_date = $row['contract_end_date'];
                        } else {
                            $contract_end_date = date('Y-m-d', strtotime("+1 year"));
                        }

                    {/php}

                    <input type="text" class="datetimepicker" id="c-contract_start_date" name="row[contract_start_date]" data-date-format="YYYY-MM-DD" value="{$contract_start_date}">

                    ～

                    <input type="text" class="datetimepicker" id="c-contract_end_date" name="row[contract_end_date]" data-date-format="YYYY-MM-DD" value="{$contract_end_date}">
                    <br/>
                    <span id="yinian" style="color:red">“上海申瑞人力资源有限公司-劳动合同”期限为：壹年</span>
                </div>
            </div>
            <div class="form-group shiyongqi_div">
                <label class="control-label col-xs-12 col-sm-2">试用期几个月:</label>
                <div class="col-xs-12 col-sm-8">
                    {php}
                        if ($row['internship_start_date']) {
                            $internship_start_date = $row['internship_start_date'];
                        } else {
                            $internship_start_date = date('Y-m-d');
                        }

                        if ($row['internship_end_date']) {
                            $internship_end_date = $row['internship_end_date'];
                        } else {
                            $internship_end_date = date('Y-m-d', strtotime("+3 month"));
                        }

                        if (!$row['internship_months']) {
                            $row['internship_months'] = 3;
                        }

                    {/php}

                    <input class="shiyongqi" id="c-internship_months" style="width:150px" placeholder="" data-rule="required" min="0" class="form-control" name="row[internship_months]" type="number" value="{$row.internship_months}">

                    <br/>

                    <input class="shiyongqi" type="text" class="datetimepicker" id="c-internship_start_date" name="row[internship_start_date]" data-date-format="YYYY-MM-DD" value="{$internship_start_date}">

                    ～

                    <input class="shiyongqi" type="text" class="datetimepicker" id="c-internship_end_date" name="row[internship_end_date]" data-date-format="YYYY-MM-DD" value="{$internship_end_date}">
                </div>

            </div>

            <hr style="display:none" class="buchong" />
            {if $row['other_data']}
            {foreach $row['other_data'] as $key=>$list}
            <input type="hidden" id="{$key}" value="{$list}">
            {/foreach}
            {/if}
            <h3 style="display:none" class="buchong" >合同其它参数</h3>
            <div style="display:none" class="buchong" id="buchong_body">
            </div>

            <hr/>
            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-3">{if $contract_status_text}合同状态：<span style="color:red">{$contract_status_text}</span>{/if}</label>
                <div class="col-xs-12 col-sm-8">
                    {if $contract_status_text != '已签署'}
                        {if $row.flowid == ''}
                        <button id="submit" type="button" class="btn btn-primary btn-embossed ">生成电子合同</button>
                        {else}
                        <button id="submit" type="button" class="btn btn-primary btn-embossed ">重新生成电子合同</button>
                        <button onclick="cancelcontract('{$row.flowid}')" type="button" class="btn btn-danger btn-embossed ">仅撤销电子合同</button>
                        {/if}

                    {/if}
                </div>

            </div>

            <div class="form-group">
                <label class="control-label col-xs-12 col-sm-3"></label>
                <div class="col-xs-12 col-sm-8" style="color:black;font-weight: bold;">
                {if $contract_status_text != '已签署' && $row.flowid}
                   注意：“重新生成电子合同”会将之前已生成的电子合同撤销，然后再生成新的电子合同！
                {/if}
                </div>
            </div>
        </form>
        </div>

        <div role="tabpanel" class="tab-pane" id="profile">
                <table style="margin-top: 20px;" class="table table-bordered">
                    <tr>
                        <th>时间</th>
                        <th>合同流</th>
                        <th>合同状态</th>
                        <!-- <th>跟进内容</th> -->
                    </tr>

                    {if $contractRecordList}
                    {foreach $contractRecordList as $list}
                    <tr>
                        <th>{$list['createtime']|date="Y-m-d H:i:s", ###}</th>
                        <th>{$list['flowid']|htmlentities}</th>
                        <th>{$list['contract_status_text2']|htmlentities}</th>
                        <!-- <th>{$list['content']|htmlentities}</th> -->
                    </tr>
                    {/foreach}
                    {/if}

                </table>
        </div>

</div>

<script type="text/javascript" src="__CDN__/assets/libs/jquery/dist/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
    var status = 1;
    $('#submit').click(function() {
        if (status == 0) {
            return false;
        }
        status = 0

        $('#edit-form').submit();

        setTimeout(function() {
            status = 1;
        }, '3000');

    });



});

function cancelcontract(flowid) {
    $.post("{:url('staff/cancelcontract')}", {flowid:flowid}, function(res) {
        if (res.code==1) {
            layer.msg(res.msg);
        } else if (res.code == 0) {
            layer.msg('撤销成功！');

            setTimeout(function() {
                // 刷新页面
                window.location.reload();
            }, '2000')
        }
    }, 'json');
}
</script>